package cn.tedu.zhwy.user.service.impl;

import cn.tedu.zhwy.base.exception.ServiceException;
import cn.tedu.zhwy.base.response.StatusCode;
import cn.tedu.zhwy.user.mapper.UserMapper;
import cn.tedu.zhwy.user.pojo.dto.UserLoginParam;
import cn.tedu.zhwy.user.pojo.vo.UserVO;
import cn.tedu.zhwy.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public UserVO login(UserLoginParam userLoginParam) {
        log.debug("用户登录，参数：{}",userLoginParam);
        UserVO userVO = userMapper.selectByUsername(userLoginParam.getUsername(), userLoginParam.getPassword());
        if(userVO==null){
            throw new ServiceException(StatusCode.USERNAME_PASSWORD_ERROR);
        }
        return userVO;
    }

    @Override
    public List<UserVO> select(UserLoginParam userLoginParam) {
        List<UserVO> userVOList = userMapper.select(userLoginParam);
        return userVOList;
    }
}
